package com.xiaomo.gitee.datamanager.aspect.log.service.impl;

import com.xiaomo.gitee.datamanager.aspect.log.SysLogBO;
import com.xiaomo.gitee.datamanager.aspect.log.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
@Slf4j
public class SysLogServiceImpl implements SysLogService {

    @Override
    public void save(SysLogBO sysLogBO) {
        log.info(format(sysLogBO));
    }

    @Override
    public String format(SysLogBO sysLogBO) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("操作: ").append(sysLogBO.getMsg());
        stringBuilder.append(" ,执行时间: ").append(sysLogBO.getExecuteTime()).append("ms");
        stringBuilder.append(" ,用户: ").append(sysLogBO.getUsername());
        for (Map.Entry<String, Object> msg : sysLogBO.getCustomMsg()) {
            stringBuilder.append(" ,").append(msg.getKey()).append(": ").append(msg.getValue());
        }
        for (Map.Entry<String, Object> msg : sysLogBO.getAnnotationCustomMsg()) {
            stringBuilder.append(" ,").append(msg.getKey()).append(": ").append(msg.getValue());
        }
        stringBuilder.append(" ,类名: ").append(sysLogBO.getClassName());
        stringBuilder.append(" ,方法名: ").append(sysLogBO.getMethodName());
        return stringBuilder.toString();
    }
}
